package com.water.auth.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.http.HttpServletRequest;

@Controller
public class PageController {
    @GetMapping("/login")
    public String login() {
        return "login"; // ✅ 渲染 `templates/login.html`
    }
    
    @GetMapping("/logout")
    public String logout() {
        return "logout"; // ✅ 渲染 `templates/login.html`
    }
    
    @GetMapping("/customlogin")
    public String customLogin() {
        return "custom-login"; // ✅ 渲染 `templates/custom-login.html`
    }
    
    @GetMapping("/error")
    public String handleError(HttpServletRequest request, Model model) {
        Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
        if (status != null) {
            model.addAttribute("errorCode", status.toString());
        }
        return "error";
    }
}
